# app/services/family/pet.py
from typing import Optional, List
from app.core.crud import CRUDBase
from app.models.family.pet import Pet
from app.schemas.family.pet import PetCreate, PetUpdate
from tortoise.expressions import Q

class PetService(CRUDBase[Pet, PetCreate, PetUpdate]):
    def __init__(self):
        super().__init__(model=Pet)

    async def get_pet_by_family(self, pet_id: int,family_id:int = None) -> Optional[Pet]:
        """根据宠物ID获取宠物"""
        return await self.model.filter(id=pet_id,family_id = family_id,is_deleted=False).first()

    async def list_pets_by_family(self, family_id: int, page: int = 1, page_size: int = 10) -> List[Pet]:
        """根据家庭ID获取宠物列表"""
        return await self.model.filter(family_id=family_id, is_deleted=False).offset((page-1)*page_size).limit(page_size)

pet_service = PetService()